<?php

// +----------------------------------------------------------------------
// |Author: 翼小菜
// +----------------------------------------------------------------------
// |Description: Rbac 逻辑层
// +----------------------------------------------------------------------
// |更多功能可联系QQ314688769
// +----------------------------------------------------------------------
namespace api\cveadmin\service;

class RbacService
{
    public function getTree($data, $pid = 0, $level = 0)
	{
		// $level 是可选
		$tree = [];
		foreach($data as $k => $v) {
			if ($v['parent_id'] === $pid) {
				$v['level'] = $level;
				$child = $this->getTree($data, $v['id'], $level+1);
				if (!empty($child)) {
					// 自定义children字段，存放子数据
					$v['children'] = $child;
				}
				//最高设置三层 将$v push到$tree中，多维数组
				if($level < 3){
					$tree[] = $v;
				}
			}
		}
		return $tree;
	}
}
